#pragma once

#include <Windows.h>

#define SystemModuleInformation (SYSTEM_INFORMATION_CLASS)11
#define SystemHandleInformation (SYSTEM_INFORMATION_CLASS)16

//0x18 bytes (sizeof)
struct _DISPATCHER_HEADER
{
    union
    {
        volatile LONG Lock;                                                 //0x0
        LONG LockNV;                                                        //0x0
        struct
        {
            UCHAR Type;                                                     //0x0
            UCHAR Signalling;                                               //0x1
            UCHAR Size;                                                     //0x2
            UCHAR Reserved1;                                                //0x3
        };
        struct
        {
            UCHAR TimerType;                                                //0x0
            union
            {
                UCHAR TimerControlFlags;                                    //0x1
                struct
                {
                    UCHAR Absolute : 1;                                       //0x1
                    UCHAR Wake : 1;                                           //0x1
                    UCHAR EncodedTolerableDelay : 6;                          //0x1
                };
            };
            UCHAR Hand;                                                     //0x2
            union
            {
                UCHAR TimerMiscFlags;                                       //0x3
                struct
                {
                    UCHAR Index : 6;                                          //0x3
                    UCHAR Inserted : 1;                                       //0x3
                    volatile UCHAR Expired : 1;                               //0x3
                };
            };
        };
        struct
        {
            UCHAR Timer2Type;                                               //0x0
            union
            {
                UCHAR Timer2Flags;                                          //0x1
                struct
                {
                    UCHAR Timer2Inserted : 1;                                 //0x1
                    UCHAR Timer2Expiring : 1;                                 //0x1
                    UCHAR Timer2CancelPending : 1;                            //0x1
                    UCHAR Timer2SetPending : 1;                               //0x1
                    UCHAR Timer2Running : 1;                                  //0x1
                    UCHAR Timer2Disabled : 1;                                 //0x1
                    UCHAR Timer2ReservedFlags : 2;                            //0x1
                };
            };
            UCHAR Timer2ComponentId;                                        //0x2
            UCHAR Timer2RelativeId;                                         //0x3
        };
        struct
        {
            UCHAR QueueType;                                                //0x0
            union
            {
                UCHAR QueueControlFlags;                                    //0x1
                struct
                {
                    UCHAR Abandoned : 1;                                      //0x1
                    UCHAR DisableIncrement : 1;                               //0x1
                    UCHAR QueueReservedControlFlags : 6;                      //0x1
                };
            };
            UCHAR QueueSize;                                                //0x2
            UCHAR QueueReserved;                                            //0x3
        };
        struct
        {
            UCHAR ThreadType;                                               //0x0
            UCHAR ThreadReserved;                                           //0x1
            union
            {
                UCHAR ThreadControlFlags;                                   //0x2
                struct
                {
                    UCHAR CycleProfiling : 1;                                 //0x2
                    UCHAR CounterProfiling : 1;                               //0x2
                    UCHAR GroupScheduling : 1;                                //0x2
                    UCHAR AffinitySet : 1;                                    //0x2
                    UCHAR Tagged : 1;                                         //0x2
                    UCHAR EnergyProfiling : 1;                                //0x2
                    UCHAR SchedulerAssist : 1;                                //0x2
                    UCHAR ThreadReservedControlFlags : 1;                     //0x2
                };
            };
            union
            {
                UCHAR DebugActive;                                          //0x3
                struct
                {
                    UCHAR ActiveDR7 : 1;                                      //0x3
                    UCHAR Instrumented : 1;                                   //0x3
                    UCHAR Minimal : 1;                                        //0x3
                    UCHAR Reserved4 : 2;                                      //0x3
                    UCHAR AltSyscall : 1;                                     //0x3
                    UCHAR Emulation : 1;                                      //0x3
                    UCHAR Reserved5 : 1;                                      //0x3
                };
            };
        };
        struct
        {
            UCHAR MutantType;                                               //0x0
            UCHAR MutantSize;                                               //0x1
            UCHAR DpcActive;                                                //0x2
            UCHAR MutantReserved;                                           //0x3
        };
    };
    LONG SignalState;                                                       //0x4
    struct _LIST_ENTRY WaitListHead;                                        //0x8
};

//0x18 bytes (sizeof)
struct _KEVENT
{
    struct _DISPATCHER_HEADER Header;                                       //0x0
};

//0x18 bytes (sizeof)
struct _RTL_BALANCED_NODE
{
    union
    {
        struct _RTL_BALANCED_NODE* Children[2];                             //0x0
        struct
        {
            struct _RTL_BALANCED_NODE* Left;                                //0x0
            struct _RTL_BALANCED_NODE* Right;                               //0x8
        };
    };
    union
    {
        struct
        {
            UCHAR Red : 1;                                                    //0x10
            UCHAR Balance : 2;                                                //0x10
        };
        ULONGLONG ParentValue;                                              //0x10
    };
};

//0x20 bytes (sizeof)
struct _IOP_MC_BE_PAGE_NODE
{
    struct _RTL_BALANCED_NODE Node;                                         //0x0
    ULONG PageIndex;                                                        //0x18
};

//0x80 bytes (sizeof)
struct _IOP_MC_BUFFER_ENTRY
{
    USHORT Type;                                                            //0x0
    USHORT Reserved;                                                        //0x2
    ULONG Size;                                                             //0x4
    LONG ReferenceCount;                                                    //0x8
    enum _IOP_MC_BUFFER_ENTRY_FLAGS Flags;                                  //0xc
    struct _LIST_ENTRY GlobalDataLink;                                      //0x10
    VOID* Address;                                                          //0x20
    ULONG Length;                                                           //0x28
    CHAR AccessMode;                                                        //0x2c
    LONG MdlRef;                                                            //0x30
    struct _MDL* Mdl;                                                       //0x38
    struct _KEVENT MdlRundownEvent;                                         //0x40
    ULONGLONG* PfnArray;                                                    //0x58
    struct _IOP_MC_BE_PAGE_NODE PageNodes[1];                               //0x60
};

//0x8 bytes (sizeof)
struct _NT_IORING_CREATE_FLAGS
{
    enum _NT_IORING_CREATE_REQUIRED_FLAGS Required;                         //0x0
    enum _NT_IORING_CREATE_ADVISORY_FLAGS Advisory;                         //0x4
};

//0x30 bytes (sizeof)
struct _NT_IORING_INFO
{
    enum IORING_VERSION IoRingVersion;                                      //0x0
    struct _NT_IORING_CREATE_FLAGS Flags;                                   //0x4
    ULONG SubmissionQueueSize;                                              //0xc
    ULONG SubmissionQueueRingMask;                                          //0x10
    ULONG CompletionQueueSize;                                              //0x14
    ULONG CompletionQueueRingMask;                                          //0x18
    struct _NT_IORING_SUBMISSION_QUEUE* SubmissionQueue;                    //0x20
    struct _NT_IORING_COMPLETION_QUEUE* CompletionQueue;                    //0x28
};

//0xd0 bytes (sizeof)
struct _IORING_OBJECT
{
    SHORT Type;                                                             //0x0
    SHORT Size;                                                             //0x2
    struct _NT_IORING_INFO UserInfo;                                        //0x8
    VOID* Section;                                                          //0x38
    struct _NT_IORING_SUBMISSION_QUEUE* SubmissionQueue;                    //0x40
    struct _MDL* CompletionQueueMdl;                                        //0x48
    struct _NT_IORING_COMPLETION_QUEUE* CompletionQueue;                    //0x50
    ULONGLONG ViewSize;                                                     //0x58
    LONG InSubmit;                                                          //0x60
    ULONGLONG CompletionLock;                                               //0x68
    ULONGLONG SubmitCount;                                                  //0x70
    ULONGLONG CompletionCount;                                              //0x78
    ULONGLONG CompletionWaitUntil;                                          //0x80
    struct _KEVENT CompletionEvent;                                         //0x88
    UCHAR SignalCompletionEvent;                                            //0xa0
    struct _KEVENT* CompletionUserEvent;                                    //0xa8
    ULONG RegBuffersCount;                                                  //0xb0
    struct _IOP_MC_BUFFER_ENTRY** RegBuffers;                               //0xb8
    ULONG RegFilesCount;                                                    //0xc0
    VOID** RegFiles;                                                        //0xc8
};
